package com.example.dense_rack_server.security.handler;

import com.example.dense_rack_server.security.dto.JwtUserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 退出回调
 */
@Slf4j
@Component
public class MyLogoutHandler implements LogoutHandler {
    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        JwtUserDto userDetails = (JwtUserDto) authentication.getPrincipal();//拿到登录用户信息

        //保存退出日志
//        LoginLog loginLog = new LoginLog();
//        loginLog.setUserId(userDetails.getMyUser().getUserId());
//        loginLog.setType(2);
//        loginLog.setIp(ipUtils.getIp(request));
//        loginLog.setCreateTime(DateFormat.getTime());
//        loginLog.setBrowser(ipUtils.getBrowser(request));
//        loginLog.setOsName(ipUtils.getOs(request));
//        LoginLogService loginLogService = Application.ac.getBean(LoginLogService.class);
//        loginLogService.save(loginLog);
    }
}
